package com.sy.jtabytetcc.controller;


import java.util.Optional;

import org.bytesoft.compensable.Compensable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.sy.jtabytetcc.dao.RepoAReposity;
import com.sy.jtabytetcc.pojo.RepoA;
import com.sy.jtabytetcc.service.IRepoAService;
import com.sy.jtabytetcc.service.RepoAService;

@RestController
@Compensable(interfaceClass = IRepoAService.class,
confirmableKey = "repoAServiceConfirm",
cancellableKey = "repoAServiceCancel")
public class RepoAController implements IRepoAService {
	@Autowired
	private RepoAService repoAService;
//	@Autowired
//	private JdbcTemplate jdbcTemplate;

//    @ResponseBody
//    @GetMapping("/tradingItems")
//    @Transactional
//    public String tradingItems() {
//    	Integer sourceId = 1;
//    	Integer targetId =1;
//    	Integer count = 2;
//        this.repoAService.tradingItems(sourceId, targetId, count);
//        return "操作成功";
//    }
    
    @ResponseBody
    @GetMapping("/tradingItems")
    @Transactional
	@Override
	public void tradingItems(Integer sourceRepoId, Integer targetRepoId, Integer count) {
//    	sourceRepoId = 1;
//    	targetRepoId =1;
//    	 count = 2;
        this.repoAService.tradingItems(sourceRepoId, targetRepoId, count);
//    	int update = jdbcTemplate.update("update repo_a set freeze=freeze+? where id=? and (stocks-freeze-?)>0",count,sourceRepoId,count);
//    	if(update==0) {
//    		throw new RuntimeException("更新异常");
//    	}
	}
    

}
